home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_084 / ed / doread.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  1KB  |  64 lines

  1. /*
  2.  * Copyright 1987 Brian Beattie Rights Reserved.
  3.  *
  4.  * Permission to copy and/or distribute granted under the
  5.  * following conditions:
  6.  *
  7.  * 1). No charge may be made other than resonable charges
  8.  *    for reproduction.
  9.  *
  10.  * 2). This notice must remain intact.
  11.  *
  12.  * 3). No further restrictions may be added.
  13.  *
  14.  */
  15. #include <stdio.h>
  16. #include "tools.h"
  17. #include "ed.h"
  18.  
  19. doread(lin, fname)
  20. int    lin;
  21. char    *fname;
  22. {
  23.     extern FILE    *fopen();
  24.     FILE    *fp;
  25.     int    err;
  26.     long    bytes;
  27.     int    lines;
  28.     static char    str[MAXLINE];
  29.  
  30.     err = 0;
  31.     nonascii = nullchar = truncated = 0;
  32.  
  33.     printf("\"%s\" ",fname);
  34.     if((fp = fopen(fname, "r")) == NULL)
  35.     {
  36.         printf("file open err\n");
  37.         return( ERR );
  38.     }
  39.     curln = lin;
  40.     for(lines = 0, bytes = 0;(err = egets(str,MAXLINE,fp)) > 0;)
  41.     {
  42.         bytes += strlen(str);
  43.         if(ins(str) < 0)
  44.         {
  45.             printf("file insert error\n");
  46.             err++;
  47.             break;
  48.         }
  49.         lines++;
  50.     }
  51.     fclose(fp);
  52.     if(err < 0)
  53.         return(err);
  54.     printf("%d lines %d bytes",lines,bytes);
  55.     if(nonascii)
  56.         printf(" [%d non-ascii]",nonascii);
  57.     if(nullchar)
  58.         printf(" [%d nul]",nullchar);
  59.     if(truncated)
  60.         printf(" [%d lines truncated]",truncated);
  61.     printf("\n");
  62.     return( err );
  63. }
  64.